const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/yxlm', { useUnifiedTopology: true, useNewUrlParser: true })
.then(() => {
    console.log('数据库连接成功');
})
.catch(err => {
    console.log(err);
    console.log('数据库连接失败');
});

// 创建集合规则
let jhgz = new mongoose.Schema({
    name: String,
    age: Number,
    sex: String
});

// 创建集合
let User = mongoose.model('User', jhgz);


// 创建集合实例

let data1 = new User({
    name: '陈雨鑫',
    age: 19,
    sex: '男'
});

data1.save();